package com.hyh.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.util.Log;

import com.hyh.videochat.R;


/**
 * Created by Administrator on 2019/1/28.
 */

public class SoundUtil implements MediaPlayer.OnCompletionListener {

    private static SoundUtil soundUtil;
    private MediaPlayer mediaPlayer;
    private int count=0;
    private SoundUtil(Context context){
        mediaPlayer = MediaPlayer.create(context, R.raw.bg_musi1c);
        mediaPlayer.setOnCompletionListener(this);
    }

    public static synchronized SoundUtil getInstance(Context context){
        if(soundUtil==null){
            soundUtil = new SoundUtil(context);
        }
        return soundUtil;
    }

    public void play(){
        if(!mediaPlayer.isPlaying()){
            mediaPlayer.start();
        }
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        if(count<2){
            count++;
            mediaPlayer.start();
        }else{
            count = 0;
        }
    }
}
